package com.woniu.apidriver.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.apidriver.service.UserService;
import com.woniu.internalcommon.dto.*;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import com.woniu.internalcommon.util.JwtUtils;
//import com.woniu.internalcommon.dto.TokenResult;

@RestController
@RequestMapping("/api-driver")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 更新司机信息
     * @param driverUser
     * @return
     */
    @PutMapping("/updateDriver")
    public ResponseResult updateUser(@RequestBody DriverUser driverUser){
        return userService.updateUser(driverUser);
    }

    /**
     * 修改司机工作状态
     * @param driverUserWorkStatus
     * @return
     */
    @PutMapping("/driver-user-work-status")
    public ResponseResult changeWorkStatus(@RequestBody DriverUserWorkStatus driverUserWorkStatus){

        return userService.changeWorkStatus(driverUserWorkStatus);
    }

    /**
     * 根据司机token查询 司机和车辆绑定关系
     * @param request
     * @return
     */
    @GetMapping("/SelectDriverCarBinding")
    public ResponseResult getDriverCarBindingRelationship(HttpServletRequest request){

        String authorization = request.getHeader("Authorization");
        TokenResult tokenResult = JwtUtils.checkToken(authorization);
        String driverPhone = tokenResult.getPhone();

        return userService.getDriverCarBindingRelationship(driverPhone);

    }

    /**
     * 根据司机id查询司机工作状态
     * @param driverId
     * @return
     */
    @GetMapping("/selectWorkStatus")
    public ResponseResult<DriverUserWorkStatus> getWorkStatus(@RequestParam("driverId") Long driverId){
        return userService.getWorkStatus(driverId);
    }

    /**
     * 查询所有车辆信息--条件+分页
     * @param apiBossCar
     * @return
     */
    @PostMapping("/getAllCar")
    public ResponseResult<Page<Car>> getAllCar(@RequestBody ApiBossCar apiBossCar){
        return userService.getAllCar(apiBossCar);
    }

    /**
     * 查询所有
     * @param
     * @return
     */
    @GetMapping("/getAll")
    public ResponseResult<Page<DriverUser>> getAll(@RequestParam("current") Integer  current, @RequestParam("size") Integer size ){
        return userService.getAll(current,size);
    }

}